<template>
  <div>
    <!-- 导入组件 -->
    <UploadExcel
      :before-upload="beforeUpload"
      :on-success="onSuccess"
    />
  </div>
</template>

<script>
import { importEmployee } from '@/api/employees'
import { getImportData } from '@/utils/excelData'
export default {
  name: 'EmUploadExcel',

  data() {
    return {

    }
  },

  methods: {
    // 上传前回调
    beforeUpload(file) {
      const isLt1M = file.size / 1024 / 1024 < 1

      if (isLt1M) {
        return true
      }

      this.$message({
        message: 'Please do not upload files larger than 1m in size.',
        type: 'warning'
      })
      return false
    },
    // 上传后回调
    async onSuccess({ results, header }) {
    //   console.log(results)
      // 处理数据
      const data = getImportData(results)
      // 调用导入接口
      await importEmployee(data)
      this.$router.back()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
